package com.yellowpage.nsp.action;
  
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.nsp.data.NspTelLog;
import com.yellowpage.nsp.service.NspTelLogService;

public class NspTelLogAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<NspTelLog> nspTelLogList = new ArrayList<NspTelLog>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private NspTelLog nspTelLog;
	private NspTelLogService nspTelLogService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_telType;
		private String query_queryNum;
		private String query_logTime;
		private String query_signNote;
		private String query_subjectNum;
		private String query_id;
		
	public void prepare() {
		super.prepare();
	
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.nspTelLog = nspTelLogService.getNspTelLog(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
			    queryMap.put("telType", query_telType);
	    	    queryMap.put("queryNum", query_queryNum);
	    	    queryMap.put("logTime", query_logTime);
	    	    queryMap.put("signNote", query_signNote);
	    	    queryMap.put("subjectNum", query_subjectNum);
	    	    queryMap.put("id", query_id);
	    	    	
		resultList = nspTelLogService.queryNspTelLogByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		nspTelLogService.saveNspTelLog(nspTelLog);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    if (nspTelLog.getTelType().length() == 0) {
			this.addActionError("** TelType 不能为空 !");
		}
			    	    	    if (nspTelLog.getQueryNum().length() == 0) {
			this.addActionError("** QueryNum 不能为空 !");
		}
			    	    	    if (nspTelLog.getLogTime().length() == 0) {
			this.addActionError("** LogTime 不能为空 !");
		}
			    	    	    if (nspTelLog.getSignNote().length() == 0) {
			this.addActionError("** SignNote 不能为空 !");
		}
			    	    	    if (nspTelLog.getSubjectNum().length() == 0) {
			this.addActionError("** SubjectNum 不能为空 !");
		}
			    	    	    	    
		this.setValidatorResult("/nsp/NspTelLogAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    nspTelLog = nspTelLogService.getNspTelLog(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    nspTelLogService.updateNspTelLog(nspTelLog);	

		message = "修改成功!";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    if (nspTelLog.getTelType().length() == 0) {
			this.addActionError("** TelType 不能为空 !");
		}
			    			    if (nspTelLog.getQueryNum().length() == 0) {
			this.addActionError("** QueryNum 不能为空 !");
		}
			    			    if (nspTelLog.getLogTime().length() == 0) {
			this.addActionError("** LogTime 不能为空 !");
		}
			    			    if (nspTelLog.getSignNote().length() == 0) {
			this.addActionError("** SignNote 不能为空 !");
		}
			    			    if (nspTelLog.getSubjectNum().length() == 0) {
			this.addActionError("** SubjectNum 不能为空 !");
		}
			    			    		this.setValidatorResult("/nsp/NspTelLogUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.nspTelLogService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲突，删除失败 !");
		}
		
		
		return queryByPage();
	}	
	
	

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setNspTelLog(NspTelLog nspTelLog) {
		this.nspTelLog = nspTelLog;
	}
	
	public NspTelLog getNspTelLog() {
		return nspTelLog;
	}
	 
	 
	 public void setNspTelLogService(NspTelLogService nspTelLogService) {
		this.nspTelLogService = nspTelLogService;
	}
	
	public List<NspTelLog> getNspTelLogList() {
		return nspTelLogList;
	}

	public void setNspTelLogList(List<NspTelLog> nspTelLogList) {
		this.nspTelLogList = nspTelLogList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_telType() {
        return this.query_telType;
    }
    
    public void setQuery_telType(String telType){
        this.query_telType = telType;
    }    

        public String getQuery_queryNum() {
        return this.query_queryNum;
    }
    
    public void setQuery_queryNum(String queryNum){
        this.query_queryNum = queryNum;
    }    

        public String getQuery_logTime() {
        return this.query_logTime;
    }
    
    public void setQuery_logTime(String logTime){
        this.query_logTime = logTime;
    }    

        public String getQuery_signNote() {
        return this.query_signNote;
    }
    
    public void setQuery_signNote(String signNote){
        this.query_signNote = signNote;
    }    

        public String getQuery_subjectNum() {
        return this.query_subjectNum;
    }
    
    public void setQuery_subjectNum(String subjectNum){
        this.query_subjectNum = subjectNum;
    }    

        public String getQuery_id() {
        return this.query_id;
    }
    
    public void setQuery_id(String id){
        this.query_id = id;
    }    

    
	
}
